package com.freesky.web.manager.controller.panel;

import com.freesky.common.dao.entity.HomeRotationChart;
import com.freesky.common.dao.mapper.HomeRotationChartMapper;
import com.freesky.common.enums.StateEnum;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.manager.remote.panel.HomeRotationChartRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 8:54 2018/12/13
 * @description: 轮播图管理
 */
@Controller
@Api(description = "轮播图管理")
public class HomeRotationChartController {

    @Autowired
    private HomeRotationChartMapper homeRotationChartMapper;
    @Autowired
    private HomeRotationChartRemote remote;

    @ApiOperation(value = "进入界面-轮播图列表")
    @GetMapping("/home/rotation-chart/page")
    public String page(Model model) {
        List<HomeRotationChart> list = homeRotationChartMapper.getAll(StateEnum.UNUSE);
        model.addAttribute("list", list);
        return "home-rotation-chart/list";
    }

    @ApiOperation(value = "进入界面-轮播图添加")
    @GetMapping(value = "/home/rotation-chart/add/page")
    public String addPage() {
        return "home-rotation-chart/add";
    }

    @ApiOperation(value = "进入界面-轮播图编辑")
    @GetMapping(value = "/home/rotation-chart/update/page")
    public String update() {
        return "home-rotation-chart/update";
    }

    @ApiOperation(value = "进入界面-轮播图选择商品")
    @GetMapping(value = "/home/rotation-chart/choose-item/page")
    public String chooseItem() {
        return "home-panel-content/choose-item";
    }

    @ResponseBody
    @PostMapping(value = "/home/rotation-chart/add")
    @ApiOperation(value = "添加轮播图")
    public JSONResponse addContent(@ModelAttribute HomeRotationChart rotationChart) {
        return remote.add(rotationChart);
    }


    @ResponseBody
    @PostMapping(value = "/home/rotation-chart/update")
    @ApiOperation(value = "修改轮播图")
    public JSONResponse update(@ModelAttribute HomeRotationChart rotationChart) {
        return remote.update(rotationChart);
    }

    @ResponseBody
    @DeleteMapping(value = "/home/rotation-chart/del/{ids}")
    @ApiOperation(value = "删除轮播图")
    public JSONResponse delete(@PathVariable int[] ids) {
        return remote.delete(ids);
    }
}
